package test.unit
{
	import com.zanshine.benchmark.core.events.BenchmarkEvent;
	import com.zanshine.benchmark.api.Benchmarkable;
	import com.zanshine.benchmark.core.CaseRunner;
	
	import net.digitalprimates.fluint.tests.TestCase;
	
	import test.mock.*;

	public class CaseRunnerIterationTest extends TestCase
	{
		private var benchTest:Benchmarkable;
		private var benchRunner:CaseRunner;
		
		private static const METHOD_COUNT:uint = 5;
		private static const BENCH_COUNT:uint = 3;
		private static const TOTAL_METHOD_COUNT:uint = METHOD_COUNT * BENCH_COUNT;
		private static const DELAY:uint = 50;
		
		/**
		 * 
		 */
		public function testMethodIterationCount():void
		{
			benchTest = new IterationsCountMockBenchTest();
			benchRunner = new CaseRunner(benchTest, METHOD_COUNT);
			benchRunner.addEventListener(
				BenchmarkEvent.CASE_RUNNED, 
				asyncHandler(async_testMethodIterationCount, 50)
			);
			benchRunner.run();
		}
		
		private function async_testMethodIterationCount(event:BenchmarkEvent, data:Object):void
		{			
			assertEquals(
				METHOD_COUNT, 
				IterationsCountMockBenchTest(benchTest).methodCalls
			);
		}
		
		/**
		 * 
		 */
		public function testBenchIterationCount():void
		{	
			benchTest = new IterationsCountMockBenchTest();
			benchRunner = new CaseRunner(benchTest, METHOD_COUNT, BENCH_COUNT, DELAY);
			benchRunner.addEventListener(
				BenchmarkEvent.CASE_RUNNED, 
				asyncHandler(async_testBenchIterationCount, BENCH_COUNT * DELAY * 3.5)
			);
			benchRunner.run();
		}
		
		private function async_testBenchIterationCount(event:BenchmarkEvent, data:Object):void
		{			
			assertEquals(
				TOTAL_METHOD_COUNT, 
				IterationsCountMockBenchTest(benchTest).methodCalls
			);
		}
	}
}